package com.peas.platform.module.icims.base.approve.service.impl;

import com.peas.platform.common.core.configuration.RequestContextUtil;
import com.peas.platform.framework.mybatisplus.domain.BaseDomain;
import com.peas.platform.framework.mybatisplus.po.BasePo;
import com.peas.platform.framework.mybatisplus.service.BaseServiceImpl;
import com.peas.platform.module.icims.base.approve.domain.ApproveOrderOperDomain;
import com.peas.platform.module.icims.base.approve.dto.ApproveOrderDto;
import com.peas.platform.module.icims.base.approve.dto.ApproveOrderOperDto;
import com.peas.platform.module.icims.base.approve.enums.ApproveOrderBusinessType;
import com.peas.platform.module.icims.base.approve.enums.ApproveOrderOperType;
import com.peas.platform.module.icims.base.approve.service.ApproveOrderOperService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class ApproveOrderOperServiceImpl extends BaseServiceImpl<ApproveOrderOperDto> implements ApproveOrderOperService {

    @Resource
    private ApproveOrderOperDomain approveOrderOperDomain;

    @Override
    public BaseDomain<ApproveOrderOperDto, ? extends BasePo> getDomain() {
        return approveOrderOperDomain;
    }

    @Transactional
    @Override
    public void saveApproveOrderOper(ApproveOrderOperType type, ApproveOrderDto aod, Integer currentNo, String currentName, String approveResult, String approveOpinion, ApproveOrderBusinessType businessType, Long businessId) {
        Long currentUserId = Long.valueOf(RequestContextUtil.getCurrentUserId(true));
        ApproveOrderOperDto aood = new ApproveOrderOperDto();
        aood.setApproveOrderOperType(type.getKey());
        if (aod != null) {
            aood.setApproveOrderId(aod.getId());
            aood.setApproveOrderCode(aod.getApproveOrderCode());
            aood.setApproveOrderName(aod.getApproveOrderName());
        }
        aood.setCurrentApproveUserId(currentUserId);
        aood.setCurrentNo(currentNo);
        aood.setCurrentName(currentName);
        aood.setApproveResult(approveResult);
        aood.setApproveOpinion(approveOpinion);
        aood.setBusinessType(businessType.getKey());
        aood.setBusinessId(businessId);
        aood.setBusinessUrl(null);
        this.save(aood);
    }

}
